<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('公文管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>公文标题：</label>
                                <input type="text" name="arrangeTitle"/>
                            </li>
                            <li>
                                <label>发起人：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <label>重要程度：</label>
                                <select name="documentImportance" th:with="type=${@dict.getType('document_importance')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('document_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()" shiro:hasPermission="document:arrange:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editFull()" shiro:hasPermission="document:arrange:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="document:arrange:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('document:arrange:edit')}]];
        var removeFlag = [[${@permission.hasPermi('document:arrange:remove')}]];
        var documentImportanceDatas = [[${@dict.getType('document_importance')}]];
        var websiteTipsDatas = [[${@dict.getType('is_tips')}]];
        var smsTipsDatas = [[${@dict.getType('is_tips')}]];
        var statusDatas = [[${@dict.getType('document_status')}]];
        var prefix = ctx + "document/arrange";

        $(function() {
            var options = {
                url: prefix + "/personalList",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "公文管理",
                sortName: "createTime",
		        sortOrder: "desc",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'arrangeId',
                    title: '公文ID',
                    visible: false
                },
                {
                    field: 'arrangeTitle',
                    title: '公文标题'
                },
                {
                    field: 'documentImportance',
                    title: '重要程度',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(documentImportanceDatas, value);
                    }
                },
                {
                    field: 'startDate',
                    title: '开始日期'
                },
                {
                    field: 'endDate',
                    title: '结束日期'
                },
                {
                    field: 'status',
                    title: '工作状态',
                    formatter: function(value, row, index) {
                        if("2"===value){
                            //禁用
                            $('#toolbar .multiple').toggleClass('disabled');
                            $('#toolbar .single').toggleClass('disabled');
                        }
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'total',
                    title: '参与人数'
                },
                {
                    field: 'userName',
                    title: '发起人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if("1" == row.status){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="release(\'' + row.arrangeId + '\')"><i class="fa fa-edit"></i>发布</a> ');
                        }
                        if("2" == row.status){
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="withdraw(\'' + row.arrangeId + '\')"><i class="fa fa-remove"></i>撤回</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function release(arrangeId){
            var url = prefix + "/release";
            updateStatus(url,arrangeId);
        } 

        function withdraw(arrangeId){
            var url = prefix + "/withdraw";
            updateStatus(url,arrangeId);
        }

        function updateStatus(url,arrangeId){
            $.ajax({
				cache : true,
				type : "POST",
				url : url,
				data : {
					"arrangeId": arrangeId,
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
        }
    </script>
</body>
</html>